package com.aia.aia2.web;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
import org.json.JSONObject;

import com.aia.aia2.domain.Formdata;
import com.aia.aia2.persistence.dao.FormdataDAO;
import com.aia.prm.BeanFactory;
import com.cfh.util.Tools;

public class MyHelper {
	private static final Logger logger = Logger.getLogger(MyHelper.class);
	private static final String NULL_OBJECT = "null";

	private MyHelper() {
	}

	public static void main(String[] args) {
		BeanFactory.get().setWebApp(false);
		System.out.println(MyHelper.toFormdataJson("3F65A75A-5B09-51D0-22FB-42ED82D33AF8"));
	}

	public static String toFormdataJson(String refid) {
		if (!Tools.hasText(refid)) {
			return NULL_OBJECT;
		}
		try {
			FormdataDAO formdataDAO = (FormdataDAO) BeanFactory.get().getBean("formdataDAO");
			Formdata vo = formdataDAO.selectByPrimaryKey(refid);
			if (vo == null) {
				return NULL_OBJECT;
			}
			Map<String, Object> prepareMap = new HashMap<String, Object>();
			prepareMap.put("FD_GUID", vo.getFD_GUID());
			prepareMap.put("GI_ID", vo.getGI_ID());
			prepareMap.put("FD_COUNT", vo.getFD_COUNT());
			prepareMap.put("FD_PLAN", vo.getFD_PLAN());
			prepareMap.put("FD_INPUT", vo.getFD_INPUT());
			prepareMap.put("FD_NAME", vo.getFD_NAME());
			prepareMap.put("FD_SEX", vo.getFD_SEX());
			prepareMap.put("FD_COMPANY", vo.getFD_COMPANY());
			prepareMap.put("FD_SERVICE", vo.getFD_SERVICE());
			prepareMap.put("FD_PROVINCE", vo.getFD_PROVINCE());
			prepareMap.put("FD_DISTRICT", vo.getFD_DISTRICT());
			prepareMap.put("FD_CITY", vo.getFD_DISTRICT());
			prepareMap.put("FD_PHONE", vo.getFD_PHONE());
			prepareMap.put("FD_TEL", vo.getFD_TEL());
			prepareMap.put("FD_COMPANY", vo.getFD_COMPANY());
			JSONObject jsonObject = new JSONObject(prepareMap);
			return jsonObject.toString(2);
		} catch (Throwable e) {
			logger.warn(e);
			return NULL_OBJECT;
		}
	}
}
